<script type="text/javascript" src="./../script/plugins/autocomplete/lib/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="./../script/plugins/autocomplete/lib/jquery.ajaxQueue.js"></script>
<script type="text/javascript" src="./../script/plugins/autocomplete/jquery.autocomplete.js"></script>
<link rel="stylesheet" href="./../script/plugins/autocomplete/jquery.autocomplete.css" type="text/css">
<#if formField.hidden?? && formField.hidden=="1">
	<input type=hidden name="fieldMap['${field.name}'].id"  <#if businessInstanceField?? && businessInstanceField.id??>value="${businessInstanceField.id}"</#if>>
	<input type=hidden name="fieldMap['${field.name}'].field.id"  value="${formField.field.id}">
	<input type=hidden id=${field.name} name="fieldMap['${field.name}'].value" <#if businessInstanceField?? && businessInstanceField.value??>value="${businessInstanceField.value}"</#if>></input>
<#else>
	<#if formField.readonly?? && formField.readonly=="1">
		<input type=hidden name="fieldMap['${field.name}'].id"  <#if businessInstanceField?? && businessInstanceField.id??>value="${businessInstanceField.id}"</#if>>
		<input type=hidden name="fieldMap['${field.name}'].field.id"  value="${formField.field.id}">
		<input type=hidden name="fieldMap['${field.name}'].entityId" value="<#if businessInstanceField?? && businessInstanceField.entityId??>${businessInstanceField.entityId}"</#if>>
		<#if businessInstanceField??>
			<#if businessInstanceField.displayValue??>
				${businessInstanceField.displayValue?default('')}
			<#else>
				${businessInstanceField.value?default('')}
			</#if>
		</#if>
	<#else>
		<input type=hidden name="fieldMap['${field.name}'].id"  <#if businessInstanceField?? && businessInstanceField.id??>value="${businessInstanceField.id}"</#if>>
		<input type=hidden name="fieldMap['${field.name}'].field.id"  value="${formField.field.id}">
		<input type=hidden id="${field.name}.entityId" name="fieldMap['${field.name}'].entityId" value="<#if businessInstanceField?? && businessInstanceField.entityId??>${businessInstanceField.entityId}</#if>">
		<input type="text" id=${field.name} name="fieldMap['${field.name}'].value" <#if businessInstanceField?? && businessInstanceField.value??>value="${businessInstanceField.value}"</#if> <#if formField.width??>style="width:${formField.width};"</#if> />
	</#if>
</#if>

<script>
$("#${field.name}").autocomplete(TDQS.CONTEXT_PATH+"connectPlan/planprojectLb", {
		width: $("#${field.name}").width(),
		selectFirst: false,
		dataType:'json',
		extraParams:{'tdqssid':TDQS.SESSION_ID},
		delay:600,
		mustMatch: true,
		matchCase: true,
		formatItem: function(row, i, max) {
        	return row.planItemCode + ":" + row.itemName;
	    },
	    formatMatch: function(row, i, max) {
	        return row.planItemCode;
	    },
	    formatResult: function(row) {
	        return row.itemName;
	    },
	    parse: function(data){
	    	var parsed = [];
	        for (var i = 0; i < data.length; i++) {
	            var d = data[i];
	            var value = d.itemName;
	            var result = d.planItemCode;
	
	            parsed[parsed.length] = {
	                data: d,
	                value: value,
	                result: value //返回的结果显示内容
	            };
	        }

        	return parsed;
	    }
		
}).result(function(event, data, formatted) {
	if(data != undefined){
		$(document.getElementById("${field.name}.entityId")).val(data.id);
		$("#interveneSysInvestLabel").text(data.piTotalInvestment);
		$("#interveneSysInvest").val(data.piTotalInvestment);
	}
});
</script>